# -*- coding: utf-8 -*-

import __main__
from appengine_utilities import sessions
from appengine_utilities import flash
from appengine_utilities import event
from appengine_utilities import cache
from appengine_utilities.rotmodel import ROTModel

import wsgiref.handlers
import xmw
from xmw.db import ds
from google.appengine.ext import webapp
from google.appengine.ext import db
import urllib

import logging
from xmw.db import user_mgr


    
class MainPage(xmw.RequestHandler):
    def post(self):
        """
            set the sub_req deleted 
        """
        
        self.init_session()          
        session_user = self.get_session_user()
        #logging.info("uid:%s"%str(session_user.user_id))
        #logging.info(self.request)
        (r,e)=self.get_key_from_POST("remove")
        
        (ck,e)=self.get_key_from_POST("ck")
        
        if r is None:
            return
        
        lst_sub_id=r.split("_")
        for sub_id in lst_sub_id:
            logging.info("remove with sub_req_id=%s"%str(sub_id))
            t_q=ds.Sub_Req.all()
            t_q.filter(' sub_req_id = ',sub_id)
            #t_q.filter(' status = ', ds.Sub_Req_Status.IN_TRACE)
            sub=t_q.get()
            if sub is not None:
                sub.status=ds.Sub_Req_Status.DELETE
                sub.put()
                
        #logging.info("ck=%s"%str(ck))
        return
        
    def get(self):
        self.response.out.write(self.request)
        return
    
        
def main():
  application = webapp.WSGIApplication(
                                       [
                                        ('/mine/cart', MainPage),],
                                       debug=True)
  wsgiref.handlers.CGIHandler().run(application)

if __name__ == "__main__":
  main()